# -*- coding: utf-8 -*-
__author__ = 'lztkdr'
__date__ = '2020/12/4 10:54'



class FloatRange:
    def __init__(self, start, end, step=0.1):
        self.start = start
        self.end = end
        self.step = step

    def __iter__(self):
        t = self.start
        while t <= self.end:
            yield t
            t += self.step

    def __reversed__(self):
        t = self.end
        while t >= self.start:
            yield t
            t -= self.step


# 在python中实现了__iter__方法的对象是可迭代的
for item in  FloatRange(1.0, 4.0, 0.5):
    print(item)

print('---------------------------------------------')

# 实现 __reversed__ 可以直接 reversed 对象
for x in reversed(FloatRange(1.0, 4.0, 0.5)):
    print(x)